package com.csmz.mybookreader.Utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

/**
 * Created by Administrator on 2018/4/9.
 */

public class AnalysisUtils {
    private static final String TAG = "AnalysisUtils";

    /**
     * 从SharedPreferences中读取登录用户名
     */
    public static String readLoginUserName(Context context){
        SharedPreferences sp = context.getSharedPreferences("LoginInfo", Context.MODE_PRIVATE);
        String userName=sp.getString("loginUserName","");
        Log.d(TAG, "readLoginUserName: "+userName);
        return userName;
    }

    /**
     * 清除SharedPreferences中的登录状态和登录时的用户名
     */
    public static boolean clearLoginStatus(Context context){
        SharedPreferences sp=context.getSharedPreferences("LoginInfo", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor=sp.edit();  //获取编辑器
        editor.putBoolean("isLogin",false);         //清除登录状态
        editor.putString("loginUserName","");       //清除用户名
        editor.commit();
        return true;
    }
}
